package hhpoll

class User {

    String email
    String password
    String firstName
    String lastName
    String alias
    Date createDate = new Date()

    static hasMany = [pollParticipants:PollParticipant]
    static constraints = { 
        email(email:true,blank:false)
        firstName(blank:false)
        lastName(blank:false)
        password(minSize:6,maxSize:30)
        alias(nullable:true)
        createDate(validator: { return (it > new Date()) })
    }

    String toString() { 
        // Return the user's alias if non null, other return firstname, lastname
        this.alias ? "${this.id}: ${this.alias}" : "${this.id}: ${this.firstName} ${this.lastName}" 
    }
}
